#include "Labeled.h"
#include "Log.h"
#include <sstream>

void Labeled::init_label(const std::string& name, int ID) {
    LOG_ENTER(OBJECT,"Labeled::init");
    LOG(OBJECT) << " name=" << name << " ID=" << ID;

    this->name = name;
    this->ID = ID;

    label = "";

    LOG_EXIT();
}

void Labeled::append_label_digit(int digit) {
    LOG_ENTER(OBJECT,"Labeled::append_label_digit");

    if (0 <= digit && digit <= 9) {
        label.append(1, '0' + digit);
    }
    else if (10 <= digit && digit <= 36) {
        // like hexadecimal, but up to 'Z'
        label.append(1, (char)('A'+digit-10));
    }
    else {
        // general case, generate a multi-digit number in ASCII
        std::ostringstream s;
        s << '(' << digit << ')';
        label.append(s.str());
    }

    LOG_EXIT();
}
